#!/bin/bash
###############################################################################
# @用例ID: 20221027-172920-136492094
# @用例名称: command-execute-whitelist
# @用例级别: 3
# @用例标签:
# @用例类型: 功能测试
# @自动化: 1
###############################################################################
[ -z "$TST_TS_TOPDIR" ] && {
    TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")"
    export TST_TS_TOPDIR
}
source "${TST_TS_TOPDIR}/tst_common/lib/common.sh" || exit 1
###############################################################################

g_tmpdir="$(mktemp -d)"

tc_setup() {
    msg "this is tc_setup"
    # @预置条件: 系统正常部署
    msg "g_tmpdir=$g_tmpdir"
    return 0
}

do_test() {
    msg "this is do_test $*"

    # @测试步骤:1: 获取当前repo list和对应的基线
    local ts_release_type
    local whitelist
    local desktop_whitelist
    local service_whitelist

    if [ -n "$1" ]; then
        msg "the testcase has a arg whitelist to test: $1"
        whitelist="$(realpath "$1")"
    else
        ts_release_type="$(get_ts_release_type)"
        whitelist="$(realpath "./yum/${ts_release_type}.package.whitelist")"
    fi

    desktop_whitelist="$(realpath "$2")"
    service_whitelist="$(realpath "$3")"
    
    assert_true [ -f "$whitelist" ]
    assert_true yum clean all
    assert_true yum makecache

    # @测试步骤:2: 列出白名单的软件包并进行安装，测试其中命令是否可执行
    # @预期结果:2: 软件包安装正常，命令执行正常
    #assert_true test_package_command "$g_tmpdir" "$whitelist"
    assert_true test_package_command "$g_tmpdir" "$whitelist" "$desktop_whitelist" "$service_whitelist"

    return 0
}

tc_teardown() {
    msg "this is tc_teardown"
    #    rm -rfv "$g_tmpdir" || return 1
    return 0
}

###############################################################################
tst_main "$@"
###############################################################################
